import trinity
import blue
from actorfactory.ActorFactory import RegisterFactory
from actorfactory.ActorFactory import BaseActorFactory
PLACEABLE = 'PLACEABLE'

class PlaceableFactory(BaseActorFactory):

    def __init__(self):
        BaseActorFactory.__init__(self)



    def Register(self, factoryList):
        factoryList[PLACEABLE] = self



    def CreateObject(self, template, vPos, vForward, vNorm, properties):
        if (template.GetClassType() == PLACEABLE):
            placeable = trinity.WodPlaceable()
            placeable.placeableResPath = str(blue.rot.FilenameToPath(template.GetRes()))
            if (placeable.placeableRes == None):
                print 'Res failed to load'
                return 
            placeable.transform = self.HandleScale(template, placeable.transform)
            placeable.transform = self.HandleAlignmentForward(template, placeable.transform, vForward)
            placeable.transform = self.HandleAlignment(template, placeable.transform, vNorm)
            placeable.transform = self.HandlePosition(template, placeable.transform, vPos)
            self.HandleProperties(placeable, properties)
            return placeable



    def AddToScene(self, scene, obj, template):
        if (template.GetClassType() == PLACEABLE):
            scene.city.AddPlaceableToScene(obj)
            return True
        else:
            return False



    def IsSelfCleaning(self):
        return True



    def RemoveFromScene(self, scene, obj, template):
        if (template.GetClassType() == PLACEABLE):
            scene.city.RemovePlaceableFromScene(obj)
            return True
        else:
            return False



RegisterFactory(PlaceableFactory())

